import java.awt.Point;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;


public class Main {

	public static void main(String[] args) {

		ArrayList<Problema> listaProbs = lerProblemas();

		for (Problema problema : listaProbs) {
			//			AStar a = new AStar(problema);
			Profundidade p = new Profundidade(problema);
		}

	}

	public static ArrayList<Problema> lerProblemas(){
		ArrayList<Problema> listaProbs = new ArrayList<>();

		int numProb = 1;
		int [] [] b = new int[4][5];
		Point [][] ba = new Point[4][5];
		Estado eIni = new Estado(new Point(0,0)), eObj = new Estado(new Point(3,4));		
		// rodar o a* para lista de problemas
		// rodar o profundidade para a lista de problemas

		BufferedReader br = null;
		for (int i = 0; i < numProb; i++) {
			try {
				br = new BufferedReader(new FileReader("problema"+i+".txt"));
				int linha = 0;
				String strLinha;
				while ((strLinha = br.readLine()) != null ){
					if (linha < 5) {
						for (int j=0;j<4;j++)
							b[linha][j] = Integer.parseInt(strLinha.substring(j, j));
					} else {
						if (linha == 5) {
							String[] aux1 = strLinha.split(":");
							String[] aux2 = aux1[0].split(":");
							eIni = new Estado(new Point(Integer.parseInt(aux2[0]),Integer.parseInt(aux2[1])));

							aux2 = aux1[1].split(":");
							eObj = new Estado(new Point(Integer.parseInt(aux2[0]),Integer.parseInt(aux2[1])));
						} else {
							String[] aux1 = strLinha.split(":");
							String[] aux2 = aux1[0].split(":");
							ba[linha-6][0] = new Point(Integer.parseInt(aux2[0]),Integer.parseInt(aux2[1]));

							aux2 = aux1[1].split(":");
							ba[linha-6][1] = new Point(Integer.parseInt(aux2[0]),Integer.parseInt(aux2[1]));
						}
					}
					linha++;
				}
			} catch (FileNotFoundException e) {
			} catch (IOException e) {
			} finally {
				if ( br != null)
					try {
						br.close();
					} catch (IOException e) {
					}
			}

			//		b = { 
			//				{1,2,1,5,5}, {2,2,4,4,4}, {2,1,1,4,5}, {2,1,1,2,1}
			//		};

			//		Point [][] ba = {
			//				{new Point(2,0),new Point(2,1)}, {new Point(3,0),new Point(3,1)}, 
			//				{new Point(1,1), new Point(2,1)}, {new Point(1,2), new Point(2,2)}	
			//		};

			Problema prob = new Problema(b, ba, eIni, eObj);

			listaProbs.add(prob);
		}
		
		return listaProbs;
	}

}
